﻿using System;
using System.Windows;
using Microsoft.Services.Clab.UI.Mvvmc.Presentation.Properties;

namespace Microsoft.Services.Clab.UI.Mvvmc.Presentation
{
    public sealed class WpfViewModelMetadata : ViewModelMetadata
    {
        public WpfViewModelMetadata(WpfViewModelBase viewModel)
            : base(viewModel)
        {
        }

        public void SyncProperty(DependencyProperty viewDependencyProperty, string viewModelPropertyName)
        {
            var vm = base.viewModel as WpfViewModelBase;

            if (viewDependencyProperty == null)
            {
                throw new ArgumentNullException("viewDependencyProperty");
            }

            if (string.IsNullOrEmpty(viewModelPropertyName))
            {
                throw new ArgumentNullException("viewModelPropertyName");
            }

            if (!vm.PropertyExists(viewModelPropertyName))
            {
                throw new ArgumentException(Resources.ViewModelPropertyNotFound.FormatEx(viewModelPropertyName), "viewModelPropertyName");
            }

            vm.PropertySyncHelper.PropertyMappings.Add(new PropertySync(viewDependencyProperty, viewModelPropertyName));
        }
    }
}
